<?php
/**
 * Zend helper for theme url base
 * @uses in view template
 *      <?php echo $this->themeUrl('/path/to/action') ?>
 *      becomes
 *      http://ecom-domain.com/path/to/theme/path/to/action
 * @author Phuc Dam
 */
class Zend_View_Helper_ThemeUrl
{
    private $_themeUrl;

    /**
     * Default method for theme url helper
     * @param string $path
     * @return string
     */
    public function themeUrl($path = '')
    {
        return $this->getThemeUrl() . $path;
    }

    /**
     * Get theme url for view
     * @return <type> 
     */
    public function getThemeUrl()
    {
        if ($this->_themeUrl == null) {
            $config = Zend_Registry::get('config');
            $baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl();
            if (($position = strpos($baseUrl, '/index.php')) !== false) {
            	$baseUrl = substr($baseUrl, 0, $position);
            }

            $this->_themeUrl = $baseUrl . '/themes/' . $config['theme'];
        }
        return $this->_themeUrl;
    }

    /**
     * Set theme url for view
     * @param string $value
     */
    public function setThemeUrl($value)
    {
        $this->_themeUrl = $value;
    }
}
